一些學習:
1.Node version management. (ref:https://github.com/tj/n)
安裝:npm install -g n
2. noble 藍芽測試(mac版本)
P.S.因為有發生node.js 版本號9.2無法成功執行noble的藍芽掃描功能,所以紀錄一下。推估可能跟使用的google V8引擎有關
參考修改與新建檔案連結:https://github.com/sandeepmistry/noble/pull/689/files
npm version(command->npm -v): 5.5.1
node.js version(command->node -v):v8.9.1 (LTS版本)
新建project:
(1)mkdir XXX (建立專案目錄)
(2)cd XXX (到專案路徑下)
(3)npm init (初始化專案)
(4)npm install noble (安裝noble)
(5)到node_modules/noble/lib/mac/ 路徑下去更改 bindings.js
原始版本:
> var os = require('os');
> var osRelease = parseFloat(os.release());
>
> if (osRelease < 13 ) {
> module.exports = require('./legacy');
> } else if (osRelease < 14) {
> module.exports = require('./mavericks');
> } else {
> module.exports = require('./yosemite');
> }
修改為:
> var os = require('os');
> var osRelease = parseFloat(os.release());
>
> if (osRelease < 13 ) {
> module.exports = require('./legacy');
> } else if (osRelease < 14) {
> module.exports = require('./mavericks');
> } else if (osRelease < 17){
> module.exports = require('./yosemite');
> }else{
> module.exports = require('./highsierra');
> }
(6)新建檔案highsierra.js
檔案路徑:node_modules/noble/lib/mac/highsierra.js
P.S. kCBMsgId4為mac的藍芽引用lib
highsierra.js中第75行:
> nobleBindings.on('kCBMsgId4', function(args) {
> var state = ['unknown', 'resetting', 'unsupported', 'unauthorized', 'poweredOff', 'poweredOn'][args.kCBMsgArgState];
> debug('state change ' + state);
> this.emit('stateChange', state);
> });
執行範例測試:
到example下執行enter-exit.js檔案: node enter-exit.js